package com.pen;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pen.shardingjdbc.ShardJdbcDemoApplication;
import com.pen.shardingjdbc.entity.Course;
import com.pen.shardingjdbc.entity.User;
import com.pen.shardingjdbc.mapper.UserMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;
import java.util.Objects;

/**
 * 分表分库测试
 * 模型：数据库-m1，m2
 * 每个数据库分表有：d1，d2两张表
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ShardJdbcDemoApplication.class)
public class ShardingJdbcDemoTest3 {
    @Autowired
    UserMapper userMapper;

    @Test
    public void save() {
        User user = User.builder().userName("你好").ustatus("1").build();
        User user1 = User.builder().userName("你好").ustatus("1").build();
        User user2 = User.builder().userName("你好").ustatus("1").build();

        userMapper.insert(user);
        userMapper.insert(user1);
        userMapper.insert(user2);
    }


    @Test
    public void findById() {
        User user = userMapper.selectById(1398321068901040129L);
        System.out.println(user);
    }

    @Test
    public void findByUserId() {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", 12);


        List<User> courses = userMapper.selectList(queryWrapper);
        for (User user : courses) {
            System.out.println(user.toString());
        }
    }
    @Test
    public void findByUserIdAndId() {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", 12);


        List<User> courses = userMapper.selectList(queryWrapper);
        for (User user : courses) {
            System.out.println(user.toString());
        }
    }
}
